<template>
  <div class="dashboard-container">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card shadow="hover">
          <div class="card-header">
            <i class="el-icon-user"></i>
            <span>用户总数</span>
          </div>
          <div class="card-body">
            <span class="number">{{ stats.userCount || 0 }}</span>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover">
          <div class="card-header">
            <i class="el-icon-reading"></i>
            <span>课程总数</span>
          </div>
          <div class="card-body">
            <span class="number">{{ stats.courseCount || 0 }}</span>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover">
          <div class="card-header">
            <i class="el-icon-video-camera"></i>
            <span>视频总数</span>
          </div>
          <div class="card-body">
            <span class="number">{{ stats.videoCount || 0 }}</span>
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="6">
        <el-card shadow="hover">
          <div class="card-header">
            <i class="el-icon-document"></i>
            <span>文章总数</span>
          </div>
          <div class="card-body">
            <span class="number">{{ stats.articleCount || 0 }}</span>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import { getDashboardStats } from '@/api/dashboard'

export default defineComponent({
  name: 'Dashboard',
  setup() {
    const stats = ref({
      userCount: 0,
      courseCount: 0,
      videoCount: 0,
      articleCount: 0
    })

    const fetchStats = async () => {
      try {
        const data = await getDashboardStats()
        stats.value = data
      } catch (error) {
        console.error('获取统计数据失败:', error)
      }
    }

    onMounted(() => {
      fetchStats()
    })

    return {
      stats
    }
  }
})
</script>

<style lang="scss" scoped>
.dashboard-container {
  padding: 20px;
  
  .el-card {
    .card-header {
      display: flex;
      align-items: center;
      margin-bottom: 20px;
      
      i {
        font-size: 20px;
        margin-right: 10px;
        color: #409EFF;
      }
      
      span {
        font-size: 16px;
        color: #606266;
      }
    }
    
    .card-body {
      text-align: center;
      
      .number {
        font-size: 24px;
        font-weight: bold;
        color: #303133;
      }
    }
  }
}
</style> 